home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 January / enter-2004-01.iso / files / maxima-5.9.0.exe / {app} / share / maxima / 5.9.0 / src / mhayat.lisp < prev    next >
Encoding:
Text File  |  2003-02-09  |  11.0 KB  |  381 lines

  1. ;;; -*-  Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;;     The data in this file contains enhancments.                    ;;;;;
  4. ;;;                                                                    ;;;;;
  5. ;;;  Copyright (c) 1984,1987 by William Schelter,University of Texas   ;;;;;
  6. ;;;     All rights reserved                                            ;;;;;
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. ;;;     (c) Copyright 1980 Massachusetts Institute of Technology         ;;;
  9. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10.  
  11. (in-package "MAXIMA")
  12. (macsyma-module mhayat macro)
  13.  
  14. ;;;   **************************************************************
  15. ;;;   ***** HAYAT ******* Finite Power Series Routines *************
  16. ;;;   **************************************************************
  17. ;;;   ** (c) Copyright 1980 Massachusetts Institute of Technology **
  18. ;;;   ****** This is a read-only file! (All writes reserved) *******
  19. ;;;   **************************************************************
  20.  
  21. ;;; Note: be sure to recompile this file if any modifications are made!
  22.  
  23. ;;;        TOP LEVEL STRUCTURE
  24.  
  25. ;;;    Power series have the following format when seen outside the power
  26. ;;; series package:
  27. ;;; 
  28. ;;;    ((MRAT SIMP <varlist> <genvar> <tlist> trunc) <poly-form>)
  29. ;;; 
  30. ;;; This is the form of the output of the expressions, to
  31. ;;; be displayed they are RATDISREPed and passed to DISPLA.
  32.  
  33. ;;; The <poly-forms> consist of a header and list of exponent-coefficient
  34. ;;; pairs as shown below.  The PS is used to distinguish power series
  35. ;;; from their coefficients which have a similar representation.
  36. ;;; 
  37. ;;;   (PS (<var> . <ord-num>) (<trunc-lvl>)
  38. ;;;      (<exponent> . <coeff>) (<exponent> . <coeff>) . . .)
  39. ;;; 
  40. ;;; The <var> component of the power series is a gensym which represents the
  41. ;;; kernel of the power series.  If the package is called with the arguments:
  42. ;;; Taylor(<expr>, x, a, n)  then the kernel will be (x - a).
  43. ;;; The <ord-num> is a relative ordering for the various kernels in a
  44. ;;; multivariate expansion.  
  45. ;;; <trunc-lvl> is the highest degree of the variable <var> which is retained
  46. ;;; in the current power series.
  47. ;;; The terms in the list of exponent-coefficient pairs are ordered by
  48. ;;; increasing degree.
  49.  
  50. (declare-top (special tlist ivars key-vars last-exp))
  51.  
  52.  
  53.         (Comment Subtitle HAYAT macros)
  54.  
  55. (defmacro pszero (var pw) var pw ''(0 . 1)) ; until constants are fixed
  56.  
  57. (defmacro psp (e) `(eq (car ,e) 'ps))
  58.  
  59. (defmacro pscoefp (e) `(null (psp ,e)))
  60.  
  61. (defmacro psquo (ps1 &optional ps2)
  62.    (ifn ps2 `(psexpt ,ps1 (rcmone))
  63.       `(pstimes ,ps1 (psexpt ,ps2 (rcmone)))))
  64.  
  65. (defmacro pslog-gvar (gvar) `(pslog2 (get-inverse ,gvar)))
  66.  
  67. (defmacro gvar-o (e) `(cadr ,e))
  68.  
  69. (defmacro gvar (e) `(car (gvar-o ,e)))
  70.  
  71. (defmacro eqgvar (x y) `(eq (car ,x) (car ,y)))
  72.  
  73. (defmacro pointerp (x y) `(> (cdr ,x) (cdr ,y)))
  74.  
  75. (defmacro poly-data (p) `(caddr ,p))
  76.  
  77. (defmacro trunc-lvl (p) `(car (poly-data ,p)))
  78.  
  79. (defmacro terms (p) `(cdddr ,p))
  80.  
  81. (defmacro lt (terms) `(car ,terms))
  82.  
  83. (defmacro le (terms) `(caar ,terms))
  84.  
  85. (defmacro lc (terms) `(cdar ,terms))
  86.  
  87. (defmacro e (term) `(car ,term))
  88.  
  89. (defmacro c (term) `(cdr ,term))
  90.  
  91. (defmacro n-term (terms) `(cdr ,terms))
  92.  
  93. (defmacro mono-term? (terms) `(null (n-term ,terms)))
  94.  
  95. (defmacro nconc-terms (oldterms newterms) `(nconc ,oldterms ,newterms))
  96.  
  97. (defmacro term (e c) `(cons ,e ,c))
  98.  
  99. (defmacro make-ps (var-or-data-poly pdata-or-terms
  100.                       &optional (terms () var-pdata-case?))
  101.    (if var-pdata-case?
  102.        `(cons 'ps (cons ,var-or-data-poly (cons ,pdata-or-terms ,terms)))
  103.        `(cons 'ps (cons (gvar-o ,var-or-data-poly)
  104.             (cons (poly-data ,var-or-data-poly)
  105.                   ,pdata-or-terms)))))
  106.  
  107. ;; Be sure that PS has more than one term when deleting the first with del-lt
  108.  
  109. (defmacro del-lt (ps) `(rplacd (cddr ,ps) (cddddr ,ps)))
  110.  
  111. (defmacro add-term (terms &optional (term-or-e nil adding?) (c nil e-c?))
  112.       (cond ((null adding?) `(rplacd ,terms nil))
  113.         ((null e-c?)
  114.          `(rplacd ,terms (cons ,term-or-e (cdr ,terms))))
  115.         (`(rplacd ,terms (cons (cons ,term-or-e ,c) (cdr ,terms))))))
  116.  
  117. (defmacro add-term-&-pop (terms &rest args)
  118.    `(progn (add-term ,terms . ,args) (setq ,terms (n-term ,terms))))
  119.  
  120. ;; Keep both def'ns around until a new hayat is stable.
  121.  
  122. (defmacro change-coef (terms coef)  `(rplacd (lt ,terms) ,coef))
  123.  
  124. (defmacro change-lc (terms coef)  `(rplacd (lt ,terms) ,coef))
  125.  
  126. (defmacro getdisrep (var)  `(get (car ,var) 'disrep))
  127.  
  128. (defmacro getdiff (var)  `(get (car ,var) 'diff))
  129.  
  130. (defmacro lt-poly (p)
  131.       `(make-ps (gvar-o ,p) (poly-data ,p)
  132.               (list (lt (terms ,p)))))
  133.  
  134. (defmacro oper-name (func)  `(if (atom ,func) ,func (caar ,func)))
  135.                      
  136. (defmacro oper-namep (oper-form) `(atom ,oper-form))
  137.  
  138. (defmacro integer-subscriptp (subscr-fun)
  139.       `(apply 'and (mapcar #'integerp (cdr ,subscr-fun))))
  140.  
  141. (defmacro mlet (varl vals comp)
  142.   `(mbinding (,varl ,vals) ,comp))
  143.  
  144.  
  145. ;;; these macros access "tlist" to get various global information
  146. ;;; "tlist" is structured as a list of datums, each datum having
  147. ;;; following form:
  148. ;;;
  149. ;;;    (<var> <trunc-lvl stack> <pt of expansion>
  150. ;;;           <list of switches> <internal var = gvar> . <ord-num>)
  151. ;;;
  152. ;;; possible switches are:
  153. ;;;    $asymp = t     asymptotic expansion
  154. ;;;    multi           variable in a multivariate expansion
  155. ;;;    multivar    the actual variable of expansion in a multi-
  156. ;;;            variate expansion
  157. ;;;
  158.  
  159. ;;; macros for external people to access the tlist
  160.  
  161. ;;;    ((MRAT SIMP <varlist> <genvar> <tlist> trunc) <poly-form>)
  162.  
  163. (defmacro mrat-header (mrat) `(car ,mrat))
  164. (defmacro mrat-varlist (mrat) `(third (mrat-header ,mrat)))
  165. (defmacro mrat-genvar (mrat) `(fourth (mrat-header ,mrat)))
  166. (defmacro mrat-tlist (mrat) `(fifth (mrat-header ,mrat)))
  167. (defmacro mrat-ps (mrat) `(cdr ,mrat))
  168.  
  169. ;;; The following two macros are now functions.
  170.  
  171. ; (defmacro push-pw (datum pw)
  172. ;      `(rplaca (cdr ,datum) (cons ,pw (cadr ,datum))))
  173.  
  174. ; (defmacro pop-pw (datum)
  175. ;      `(rplaca (cdr ,datum) (cdadr ,datum)))
  176.  
  177. (defmacro datum-var (datum) `(car ,datum))
  178.  
  179. (defmacro trunc-stack (datum) `(cadr ,datum))
  180.  
  181. (defmacro current-trunc (datum) `(car (trunc-stack ,datum)))
  182.  
  183. (defmacro orig-trunc (datum) `(car (last (trunc-stack ,datum))))
  184.  
  185. (defmacro exp-pt (datum) `(caddr ,datum))
  186.  
  187. (defmacro switches (datum) `(cadddr ,datum))
  188.  
  189. (defmacro switch (sw datum) `(cdr (assq ,sw (switches ,datum))))
  190.  
  191. (defmacro int-var (datum) `(cddddr ,datum))
  192.  
  193. (defmacro data-gvar-o (data) `(cddddr ,data))
  194.  
  195. (defmacro int-gvar (datum) `(car (int-var ,datum)))
  196.  
  197. (defmacro data-gvar (data) `(car (data-gvar-o ,data)))
  198.  
  199. (defmacro get-inverse (gensym) `(cdr (assq ,gensym ivars)))
  200.  
  201. (defmacro gvar->kvar (gvar) `(cdr (assq ,gvar ivars)))
  202.  
  203. (defmacro get-key-var (gensym) `(cdr (assq ,gensym key-vars)))
  204.  
  205. (defmacro gvar->var (gvar) `(cdr (assq ,gvar key-vars)))
  206.  
  207. (defmacro dummy-var () '(cdar key-vars))
  208.  
  209. (defmacro first-datum () '(car tlist))
  210.  
  211. (defmacro get-datum (expr &optional not-canonicalized?)
  212.    (if not-canonicalized? `(assol ,expr tlist)
  213.       `(zl-ASSOC ,expr tlist)))
  214.  
  215. (defmacro var-data (var) `(zl-ASSOC ,var tlist))
  216.  
  217. (defmacro gvar-data (gvar) `(var-data (gvar->var ,gvar)))
  218.  
  219. (defmacro ps-data (ps) `(gvar-data (gvar ,ps)))
  220.  
  221. (defmacro t-o-var (gensym) `(current-trunc (get-datum (get-key-var ,gensym))))
  222.  
  223. (defmacro gvar-trunc (gvar) `(current-trunc (gvar-data ,gvar)))
  224.  
  225. (defmacro ps-arg-trunc (ps) `(gvar-trunc (gvar ,ps)))
  226.  
  227. (defmacro ps-le (ps) `(le (terms ,ps)))
  228.  
  229. (defmacro ps-le* (ps) `(if (psp ,ps) (ps-le ,ps) '(0 . 1)))
  230.  
  231. (defmacro ps-lc (ps) `(lc (terms ,ps)))
  232.  
  233. (defmacro ps-lc* (ps) `(if (psp ,ps) (ps-lc ,ps) ,ps))
  234.  
  235. (defmacro ps-lt (ps) `(lt (terms ,ps)))
  236.  
  237. (defmacro getexp-le (fun) `(car (getexp-lt ,fun)))
  238.  
  239. (defmacro getexp-lc (fun) `(cdr (getexp-lt ,fun)))
  240.  
  241. (defmacro let-pw (datum pw comp)
  242.       `(let ((d ,datum))
  243.         (prog2 (push-pw d ,pw)
  244.                ,comp
  245.                (pop-pw d))))
  246.  
  247. (defmacro if-pw (pred datum pw comp)
  248.       `(let ((p ,pred) (d ,datum))
  249.         (prog2 (and p (push-pw d ,pw))
  250.                ,comp
  251.                (and p (pop-pw d ,pw)))))
  252.  
  253. (defmacro tlist-mapc (datum-var &rest comp)
  254.       `(mapc #'(lambda (,datum-var) . ,comp) tlist))
  255.  
  256. (defmacro find-lexp (exp &optional e-start errflag accum-vars)
  257.       `(get-lexp ,exp ,e-start ,errflag ,(and accum-vars '(ncons t))))
  258.  
  259. (defmacro tay-err (msg) `(throw 'tay-err (list ,msg last-exp)))
  260.  
  261. (defmacro zero-warn (exp)
  262.   `(mtell "~%~M~%Assumed to be zero in TAYLOR~%"
  263.       `((MLABLE) () ,,exp)))
  264.  
  265.  
  266. (defmacro merrcatch (form) `(catch 'errorsw ,form))
  267.  
  268. ;There is a duplicate version of this in MAXMAC
  269. ;(defmacro infinities () ''($INF $MINF $INFINITY))
  270.  
  271. ;; Macros for manipulating expansion data in the expansion table.
  272.  
  273. (defmacro exp-datum-lt (fun exp-datum)
  274.       `(if (atom (cadr ,exp-datum))
  275.            (funcall (cadr ,exp-datum) (cdr ,fun))
  276.            (copy (cadr ,exp-datum))))
  277.  
  278. (defmacro exp-datum-le (fun exp-datum)  `(e (exp-datum-lt ,fun ,exp-datum)))
  279.  
  280. (defmacro exp-fun (exp-datum)
  281.       `(if (atom (car ,exp-datum)) (car ,exp-datum) (caar ,exp-datum)))
  282.  
  283. ;;; These macros are used to access the various extendable
  284. ;;; portions of a polynomial.
  285.  
  286. (defmacro ext-fun (p) `(cadr (poly-data ,p)))
  287.  
  288. (defmacro ext-args (p) `(caddr (poly-data ,p)))
  289.  
  290. (defmacro extendablep (p)
  291.       `((lambda (d)
  292.            (or (null (car d))
  293.                (cdr d)))
  294.        (poly-data ,p)))
  295.  
  296. (defmacro exactp (p) `(null (trunc-lvl ,p)))
  297.  
  298. (defmacro nexactp (p) `(trunc-lvl ,p))
  299.  
  300. ;;; These macros are used to access user supplied information.
  301.  
  302. (defmacro get-ps-form (fun) `(get ,fun 'sp2))
  303.  
  304. (defmacro term-disrep (term p) `(m* (srdis (c ,term))
  305.                     (m^ (get-inverse (gvar ,p))
  306.                     (edisrep (e ,term)))))
  307.  
  308.  
  309.         (comment coefficient arithmetic)
  310.  
  311. (defmacro rczero ()  ''(0 . 1))
  312.  
  313. (defmacro rcone () ''(1 . 1))
  314.  
  315. (defmacro rcfone () ''(1.0 . 1.0))
  316.  
  317. (defmacro rctwo () ''(2 . 1))
  318.  
  319. (defmacro rcmone () ''(-1 . 1))
  320.  
  321. (defmacro rczerop (r)
  322.       `(signp e (car ,r)))
  323.  
  324. (defmacro rcintegerp (c) `(and (integerp (car ,c)) (equal (cdr ,c) 1)))
  325.  
  326. (defmacro rcpintegerp (c)
  327.   `(and (rcintegerp ,c)
  328.     ;(signp g (car ,c))
  329.     ;What is this obsession with signp?  Even in maclisp it's slower
  330.     ; and more code, since it doesn't assume the thing is a number.
  331.     ;The car is integerp, after all (as implied by rcintegerp).
  332.     (plusp (car ,c))))
  333.  
  334. (defmacro rcmintegerp (c)
  335.   `(and (rcintegerp ,c)
  336.     ;(signp l (car ,c))
  337.     ;Similar to above.
  338.     (minusp (car ,c))))
  339.  
  340. (defmacro rcplus (x y) `(ratplus ,x ,y))
  341.  
  342. (defmacro rcdiff (x y) `(ratdif ,x ,y))
  343.  
  344. (defmacro rcminus (x) `(ratminus ,x))
  345.  
  346. (defmacro rctimes (x y) `(rattimes ,x ,y t))
  347.  
  348. (defmacro rcquo (x y) `(ratquotient ,x ,y))
  349.  
  350. (defmacro rcdisrep (x) `(cdisrep ,x))
  351.  
  352. (defmacro rcderiv (x v) `(ratderivative ,x ,v))
  353.  
  354. (defmacro rcderivx (x) `(ratdx1 (car ,x) (cdr ,x)))
  355.  
  356.         (comment exponent arithmetic)
  357.  
  358. ;; These macros are also used in BMT;PADE and RAT;NALGFA.
  359.  
  360. (defmacro infp (x) `(null ,x))
  361.  
  362. (defmacro inf nil nil)
  363.  
  364. (defmacro e- (e1 &optional (e2 nil 2e?))
  365.       (cond (2e? `(ediff ,e1 ,e2))
  366.         (`(cons (f- (car ,e1)) (cdr ,e1)))))
  367.  
  368. (defmacro e// (e1 &optional (e2 nil 2e?))
  369.       (cond (2e? `(equo ,e1 ,e2))
  370.         (`(erecip ,e1))))
  371.  
  372. (defmacro e>= (e1 e2) `(or (e> ,e1 ,e2) (e= ,e1 ,e2)))
  373.  
  374. (defmacro ezero () ''(0 . 1))
  375.  
  376. (defmacro eone () ''(1 . 1))
  377.  
  378. (defmacro ezerop (e) `(zerop (car ,e)))
  379.  
  380. (defmacro rcinv (r) `(ratinvert ,r))
  381.